<?php
class CV_Datastore_Builder_Form_Field{
	protected $_type;
	private $_builder;
	private $_field;
	public function __construct( $builder, $field, $type = NULL ){
		$this->_type = $type;
		$this->_builder = $builder;
		$this->_field = $field;
	}
	public function _render(){
		return $this->_builder->_render( $this, $this->get_type() );
	}	
	public function set_type( $type ){
		return $this->_type = $type;
	}
	public function get_type(){
		return $this->_field->get_type();
	}
	public function get_name(){
		return $this->_field->get_name();
	}
	public function get_id(){
		return $this->get_name();
	}
	public function get_size(){
		return min(array($this->_field->get_length(),50));
	}
	public function get_rows(){
		return 7;
	}
	public function get_cols(){
		return 3;
	}
	public function get_value(){
		if( isset($this->_builder->current_values) && array_key_exists( $this->get_name(), $this->_builder->current_values ) ){
			return $this->_builder->current_values[ $this->get_name() ];
		}		
		return $this->_field->get_default_value();
	}
	function is_shown(){
		return !$this->_field->is_readonly() || $this->_builder->current_values !== NULL;
	}
	function is_readonly(){
		return $this->_field->is_readonly();
	}
	public function is_required(){
		return !$this->_field->is_nullable() && $this->_field->get_default_value() !== "";
	}
	public function get_please_choose(){
		return 'Please choose';
	}
	public function get_label(){
		return ucwords( strtr( $this->get_name(), '_', ' ' ) );
	}
	public function has_error(){
		return false;
	}
}